import * as types from '../action-types';
export default function reducer(state={
  ambitus: {
    ambitusList : [],
    page : 1,
    kw : '',
    code : '',
    lat : '',
    lng : '',
  },
  data : {city: {name:''}},
  detail : {cover:'', name: '',activities:[]},
  userRet : '0',
  fetching: false,
  fetched: false,
  error: null,
}, action) {
  //判断类型做出对应state的改变
  switch (action.type){
    case types.FETCH_AMBITUS: {
      return {...state, fetching: true, list: []}
    }
    case types.FETCH_AMBITUS_FULFILLED: {
      if(action.payload.data){
        return {
          ...state,
          fetching: false,
          fetched: true,
          ambitus: {
            ambitusList: [...state.ambitus.ambitusList, ...action.payload.data.data],
            page : state.ambitus.page + 1,
            kw : state.ambitus.kw,
            code : state.ambitus.code
          }
        }
      }
    }
    //明细
    case types.FETCH_AMBITUS_DETAIL: {
      return {...state, fetching: true}
    }
    case types.FETCH_AMBITUS_DETAIL_FULFILLED: {
      if(action.payload.data){
        return {
          ...state,
          fetching: false,
          fetched: true,
          detail: action.payload.data
        }
      }
    }
  }
  return state;
}